home *** CD-ROM | disk | FTP | other *** search
/ Aminet 24 / Aminet 24 (1998)(GTI - Schatztruhe)[!][Apr 1998].iso / Aminet / dev / lang / PPCSmllEiffel.lha / PPCSmallEiffel / lib_se / class_name.e < prev    next >
Text File  |  1998-01-16  |  5KB  |  185 lines

  1. --          This file is part of SmallEiffel The GNU Eiffel Compiler.
  2. --          Copyright (C) 1994-98 LORIA - UHP - CRIN - INRIA - FRANCE
  3. --            Dominique COLNET and Suzanne COLLIN - colnet@loria.fr 
  4. --                       http://www.loria.fr/SmallEiffel
  5. -- SmallEiffel is  free  software;  you can  redistribute it and/or modify it 
  6. -- under the terms of the GNU General Public License as published by the Free
  7. -- Software  Foundation;  either  version  2, or (at your option)  any  later 
  8. -- version. SmallEiffel is distributed in the hope that it will be useful,but
  9. -- WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  10. -- or  FITNESS FOR A PARTICULAR PURPOSE.   See the GNU General Public License 
  11. -- for  more  details.  You  should  have  received a copy of the GNU General 
  12. -- Public  License  along  with  SmallEiffel;  see the file COPYING.  If not,
  13. -- write to the  Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  14. -- Boston, MA 02111-1307, USA.
  15. --
  16. class CLASS_NAME
  17.    --   
  18.    -- To store the base class name of a class.
  19.    --
  20.  
  21. inherit 
  22.    NAME
  23.       redefine fill_tagged_out_memory
  24.       end;
  25.    
  26. creation make
  27.    
  28. creation {BASE_CLASS}
  29.    make_unknown
  30.    
  31. feature 
  32.    
  33.    start_position: POSITION;
  34.    
  35. feature {NONE}
  36.    
  37.    make_unknown is
  38.       do
  39.      !!start_position.with(1,1,Current);
  40.      to_string := unknown_name;
  41.       end;
  42.    
  43. feature 
  44.    
  45.    make(n: STRING; sp: like start_position) is
  46.       require
  47.      n /= Void;
  48.       do
  49.      start_position := sp;
  50.      to_string := unique_string.item(n);
  51.       ensure
  52.      start_position = sp;
  53.      to_string = unique_string.item(n)
  54.       end;
  55.    
  56. feature 
  57.    
  58.    to_key: STRING is
  59.       do
  60.      Result := to_string;
  61.       end;
  62.  
  63.    fill_tagged_out_memory is
  64.       do
  65.      tagged_out_memory.append(to_string);
  66.       end;
  67.  
  68.    is_unknown: BOOLEAN is
  69.       do
  70.      Result := to_string = unknown_name;
  71.       end;
  72.    
  73.    is_subclass_of(other: CLASS_NAME): BOOLEAN is
  74.       require
  75.      to_string /= other.to_string;
  76.      eh.empty;
  77.       do
  78.      if us_any = other.to_string then
  79.         Result := true;
  80.      elseif us_none = other.to_string then
  81.      else
  82.         Result := base_class.is_subclass_of(other.base_class);
  83.      end;
  84.       ensure
  85.      eh.empty;
  86.       end;
  87.    
  88. feature 
  89.    
  90.    predefined: BOOLEAN is
  91.      -- All following classes are handled in a special way
  92.      -- by the TYPE_* corresponding class.
  93.       do
  94.      Result := (us_any = to_string or else
  95.             us_array = to_string or else
  96.             us_boolean = to_string or else
  97.             us_character = to_string or else
  98.             us_double = to_string or else
  99.             us_integer = to_string or else
  100.             us_none = to_string or else
  101.             us_pointer = to_string or else
  102.             us_real = to_string or else
  103.             us_string = to_string);
  104.       end;
  105.    
  106.    to_runnable: TYPE is
  107.      -- Return the corresponding simple (not generic) run type.
  108.       do
  109.      if us_any = to_string then
  110.         !TYPE_ANY!Result.make(start_position);
  111.      elseif us_boolean = to_string then
  112.         !TYPE_BOOLEAN!Result.make(start_position);
  113.      elseif us_character = to_string then
  114.         !TYPE_CHARACTER!Result.make(start_position);
  115.      elseif us_double = to_string then
  116.         !TYPE_DOUBLE!Result.make(start_position);
  117.      elseif us_integer = to_string then
  118.         !TYPE_INTEGER!Result.make(start_position);
  119.      elseif us_none = to_string then
  120.         !TYPE_NONE!Result.make(start_position);
  121.      elseif us_pointer = to_string then
  122.         !TYPE_POINTER!Result.make(start_position);
  123.      elseif us_real = to_string then
  124.         !TYPE_REAL!Result.make(start_position);
  125.      elseif us_string = to_string then
  126.         !TYPE_STRING!Result.make(start_position);
  127.      else        
  128.         !TYPE_CLASS!Result.make(Current);
  129.      end;
  130.       end;
  131.    
  132.    base_class: BASE_CLASS is
  133.       do
  134.      Result := small_eiffel.base_class(Current);
  135.       end;
  136.    
  137.    is_a(other: like Current): BOOLEAN is
  138.       require
  139.      other /= Void;
  140.      eh.empty;
  141.       local
  142.      to_string2: STRING;
  143.      bc1, bc2: like base_class;
  144.       do
  145.      to_string2 := other.to_string;
  146.      if us_any = to_string2 then
  147.         Result := true;
  148.      elseif to_string = to_string2 then
  149.         Result := true;
  150.      elseif us_none = to_string2 then
  151.      else
  152.         bc1 := base_class;
  153.         bc2 := other.base_class;
  154.         if bc1 = Void then
  155.            eh.append("Unable to load ");
  156.            eh.append(to_string);
  157.            error(start_position,fz_dot);
  158.         elseif bc2 = Void then
  159.            eh.append("Unable to load ");
  160.            eh.append(to_string2);
  161.            error(start_position,fz_dot);
  162.         else
  163.            Result := bc1.is_subclass_of(bc2); 
  164.         end;
  165.      end;
  166.       end;
  167.  
  168. feature {EIFFEL_PARSER}
  169.    
  170.    identify(s: STRING) is
  171.       require
  172.      is_unknown
  173.       do
  174.      to_string := unique_string.item(s);
  175.       ensure
  176.      to_string = unique_string.item(s)
  177.       end;
  178.  
  179. feature {NONE}
  180.       
  181.    unknown_name: STRING is "FOO";
  182.    
  183. end -- CLASS_NAME
  184.  
  185.